﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Data.SqlClient;
using System.IO;

namespace QL_NOI_TRU
{
    class Helper
    {

        public string Server { get; set; }
        public string Database { get; set; }
        public string UserName { get; set; }
        public string Password { get; set; }


        public Helper()
        {
            string line = "";
            StreamReader sr = new StreamReader("ConnectString.con");

            while ((line = sr.ReadToEnd().Trim()) != "")
            {
                this.Server = line;
                this.Database = line;
                this.UserName = line;
                this.Password = line;
            }
            sr.Close();


        }
        public SqlConnection GetConnect()
        {
            if (this.UserName != "")
                return new SqlConnection(String.Format("Data Source={0};Initial Catalog={1};User Id={2};Password={3};", this.Server, this.Database, this.UserName, this.Password));
            else
                return new SqlConnection(String.Format("Data Source={0};Initial Catalog={1};Integrated Security=True", this.Server, this.Database));
        }



        public static void WriteFile(string server, string data, string uid, string pass)
        {
            StreamWriter writer = new StreamWriter("ConnectString.con");
            writer.WriteLine("Server:" + server);
            writer.WriteLine("Database:" + data);
            writer.WriteLine("UserName:" + uid);
            writer.WriteLine("PassWord:" + pass);
            writer.Close();
        }
    }
}
